<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['params']=array('jy'=>1);
if($_RQ['op']=='main'){
	//下面list,PC端需要获取商品列表
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
	);
	$searchkeyword=$keywords['keyword'];
	$return['searchkeyword']=explode(';',$searchkeyword);
	$return['order']=$_RQ['order'];
	//最近浏览
	$params=array(
		//'table'=>'jy_weishop_member_history',
		'params'=>array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),
		'fields'=>array('id','goodsid','merchid','createtime'),
		'orderby'=>'createtime desc',
		'limit'=>'5',
	);
	$category=pdo_getall('jy_renwushop_group',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array(),'id','paixu desc');
	$return['category']=$category;
	if($_RQ['pcate'] || $_RQ['pid']){
		$pcate=$_RQ['pcate']?intval($_RQ['pcate']):intval($_RQ['pid']);
		$return['params']['pcate']=$pcate;
	}
	if($_RQ['ccate'] || $_RQ['cid']){
		$ccate=$_RQ['ccate']?intval($_RQ['ccate']):intval($_RQ['cid']);
		$return['params']['ccate']=$ccate;
	}
	if(isset($_RQ['type'])){
		$return['params']['type']=$_RQ['type'];
	}
	$return['catlevel']=2;
	$return['renwutypes']=$this->renwu_types;
	$return['opencategory']=true;
	set_html('title','任务列表');
	$return['sharedata']=array(
		'title'=>$return['setting']['share_title']?'全部商品'.$return['setting']['share_title']:'全部商品-拼单商城',
		'desc'=>$return['setting']['share_desc']?$return['setting']['share_desc']:'拼单商城，一个属于自己的个人商城！',
		'link'=>custom_url('jy_renwushop/renwu.index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$return['setting']['share_image']
	);
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
		'isstop'=>0
	);
	if($_RQ['type'] && $_RQ['type']!=100){
		$params['type']=$_RQ['type'];
		$return['params']['type']=$_RQ['type'];
	}else{
		$return['params']['type']=100;
	}
	//首页-不显示今天已做过的任务
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	if($_RQ['isindex']){
		$renwuids=pdo_getall('jy_renwushop_renwuorder',array('createtime >'=>$daytime,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'renwuid','renwuid');
		if($renwuids){
			//$renwuids=array_keys($renwuids);
			//先注销，不好处理
			//$params['id <>']=$renwuids;
		}
	}
	//进一步整理筛选条件，商品属性字段是否需 要调整，商品分类如何筛选，orderby如何整理
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	if($_RQ['num']){
		$psize=$_RQ['num'];
	}
	$total='';
	$fields=array('id','title','totalnum','image','fee','type','steps');
	$list=pdo_getslice('jy_renwushop_renwu',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if(!$list){
		exi('none');
	}else{
		foreach($list as $k=>&$itemv){
			$itemv['isnum']=pdo_count('jy_renwushop_renwuorder',array('uniacid'=>$_SESSION['uniacid'],'renwuid'=>$itemv['id']),'id');
			$itemv['lastnum']=$itemv['totalnum']-$itemv['isnum'];
			$itemv['renwutypes']=array();
			$itemv['typetitle']=$this->renwu_types[$itemv['type']];
			$itemv['renwutypes'][]=$itemv['typetitle'];
			if(!$itemv['image']){
				$itemv['steps']=json_decode($itemv['steps'],true);
				foreach($itemv['steps'] as $sv){
					if($sv['type']==1 || $sv['type']==3 || $sv['type']==4){
						$itemv['image']=$sv['data'];
						break;
					}
				}
			}
			$iszuo=pdo_get('jy_renwushop_renwuorder',array('createtime >'=>$daytime,'mid'=>$_SESSION['uid'],'renwuid'=>$itemv['id']),'id');
			if($iszuo['id']){
				unset($list[$k]);
			}
		}
	}
	$list=array_values($list);
	exi($list);
}
?>